#include <algorithm>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

/*
 *这个就是对数器的模板代码，可以用来测试题目
 * */

// 正确算法（暴力解法）

int Exists2(vector<int> &nums, int k) {
  for (int i = 0; i < nums.size(); ++i) {
    if (nums[i] >= k)
      return i;
  }
  return -1;
}

// 待测试算法（Kadane算法）
int Exists(vector<int> &nums, int k) {
  int left = 0;
  int right = nums.size() - 1;
  while (left <= right) {
    int mid = left + ((right - left) >> 1);
    if (nums[mid] == k) {
      return true;
    } else if (nums[mid] < k) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  return false;
}

int MinLeft(vector<int> &nums, int k) {
  int left = 0;
  int right = nums.size() - 1;
  int ans = -1;
  while (left <= right) {
    int mid = left + ((right - left) >> 1);
    if (nums[mid] >= k) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  return ans;
}

// 随机数组生成器
vector<int> generateRandomArray(int max_size, int min_val, int max_val) {
  int size = rand() % max_size + 1; // 保证至少1个元素
  vector<int> arr(size);
  for (int i = 0; i < size; ++i) {
    arr[i] = rand() % (max_val - min_val + 1) + min_val;
  }
  return arr;
}

int main() {
  srand(time(0)); // 设置随机种子
  const int TEST_TIMES = 100;
  const int MAX_SIZE = 100;
  const int MIN_VAL = -100;
  const int MAX_VAL = 100;
  for (int i = 0; i < TEST_TIMES; ++i) {
    vector<int> arr = generateRandomArray(MAX_SIZE, MIN_VAL, MAX_VAL);
    std::sort(arr.begin(), arr.end());
    vector<int> a = arr;
    vector<int> b = arr;
    int randk = rand() % (MAX_VAL - MIN_VAL + 1) + MIN_VAL;
    int a1 = MinLeft(a, randk);
    int a2 = Exists2(b, randk);
    if (a1 != a2) {
      cout << "err" << endl;
      for (auto p = arr.begin(); p != arr.end(); ++p) {
        cout << *p << " ";
      }
      cout << endl;
      return 1;
    }
    cout<<a1<<endl;
  }
  cout << "所有 " << TEST_TIMES << " 次测试通过！" << endl;
  return 0;
}
